package com.zang.blogz.listener;

import com.zang.blogz.entity.ExceptionLog;
import com.zang.blogz.event.ExceptionLogEvent;
import com.zang.blogz.service.ExceptionLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @Author: ZVerify
 * @Description: 异常监听器
 * @DateTime: 2022/9/3 14:45
 **/
@Component
public class ExceptionLogListener {

    @Autowired
    private ExceptionLogService exceptionLogService;

    @Async
    @EventListener(ExceptionLogEvent.class)
    public void saveExceptionLog(ExceptionLogEvent exceptionLogEvent) {

        exceptionLogService.save((ExceptionLog) exceptionLogEvent.getSource());
    }
}
